﻿/**************************************************************************
创建时间:	2020/5/13
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com

描	述：
记	录：
***************************************************************************/
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace ASmile.Win.Controls
{
    public class EditDateTimePicker : DateTimePicker, IEditDCM
    {
        /// <summary>
        /// 输入框的值
        /// </summary>
        [Browsable(false)]
        public object ValueItem
        {
            set
            {
                Checked = Convert.ToBoolean(value);
                IsValueChanged = true;
            }
            get
            {
                return Checked;
            }
        }

        [Browsable(false)]
        public object DisplayItem
        {
            get
            {
                return this.Value;
            }
            set
            {
                if (DateTime.TryParse(value?.ToString(), out DateTime val))
                {
                    if (val > DateTime.MinValue) Value = val;
                }
            }
        }

        [Browsable(false)]
        public bool IsValueChanged { get; private set; }

        [Browsable(false)]
        public bool IsDisplayChanged { get; } = true;

        public void SetDefault()
        {
            Value = DateTime.Now;
            IsValueChanged = false;
        }
    }
}